package com.mysoft.gfyx.marketdevelop.service.impl;

import com.mysoft.framework.modeling.dto.*;
import com.mysoft.framework.service.AppService;
import com.mysoft.gfyx.marketdevelop.mip.GetDeveloperDataService;
import com.mysoft.gfyx.marketdevelop.mip.dto.BaseTjListResponseDto;
import com.mysoft.gfyx.marketdevelop.mip.dto.BasicRiskRequestDto;
import com.mysoft.gfyx.marketdevelop.mip.dto.BasicYcgListReponseDto;
import com.mysoft.gfyx.marketdevelop.mip.dto.GetDeveloperFilterDataRequestDto;
import com.mysoft.gfyx.marketdevelop.service.DeveloperService;
import com.mysoft.gfyx.marketdevelop.service.EnterpriseRiskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Map;
import java.util.UUID;

@Service
public class EnterpriseRiskServiceImp extends AppService implements EnterpriseRiskService {

    @Autowired
    private GetDeveloperDataService getDeveloperDataService;

    public FieldsSetting loadEnforcementFields() {
        //硬编码的获取字段逻辑
        FieldsSetting fieldsSetting = new FieldsSetting();
        fieldsSetting.setIdField("uuid");
        fieldsSetting.setFields(new ArrayList<>());
        String groupName = "developer_enforcement";
        fieldsSetting.getFields().add(new DataApiField("uuid", groupName, "RowID", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("case_no", groupName, "案件编号", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("case_date", groupName, "案件时间", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("biaodi", groupName, "执行标的（元）", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("execute_gov", groupName, "执行法院", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("supplier_name", groupName, "企业名称", FieldType.String));

        // 返回
        return fieldsSetting;
    }

    public ListDataResult loadEnforcementData(LoadDataParams options) {
        String creditCode = options.getOptions().getContext().get("id").toString();
        BasicRiskRequestDto dto = new BasicRiskRequestDto();
        dto.setKeyword(creditCode);
        dto.setPage_num(options.getPageIndex());
        dto.setPage_size(options.getPageSize());

        BasicYcgListReponseDto res = getDeveloperDataService.getEnforcementData(dto);

        ListDataResult result = new ListDataResult();
        result.setData(res.getData().getItems());
        result.setTotal(res.getData().getTotal());
        return result;
    }

    public FieldsSetting loadCaseRegistrationFields() {
        //硬编码的获取字段逻辑
        FieldsSetting fieldsSetting = new FieldsSetting();
        fieldsSetting.setIdField("uuid");
        fieldsSetting.setFields(new ArrayList<>());
        String groupName = "developer_case";
        fieldsSetting.getFields().add(new DataApiField("uuid", groupName, "RowID", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("defendant", groupName, "被告人", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("case_type", groupName, "案件类型", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("filing_date", groupName, "立案时间", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("litigant", groupName, "当事人", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("supplier_name", groupName, "企业名称", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("case_status", groupName, "案件状态", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("plaintiff", groupName, "原告", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("court", groupName, "法院", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("case_no", groupName, "案件号", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("case_reason", groupName, "案件原因", FieldType.String));

        // 返回
        return fieldsSetting;
    }

    public ListDataResult loadCaseRegistrationData(LoadDataParams options) {
        String creditCode = options.getOptions().getContext().get("id").toString();
        BasicRiskRequestDto dto = new BasicRiskRequestDto();
        dto.setKeyword(creditCode);
        dto.setPage_num(options.getPageIndex());
        dto.setPage_size(options.getPageSize());

        BasicYcgListReponseDto res = getDeveloperDataService.getCaseRegistrationData(dto);

        ListDataResult result = new ListDataResult();
        result.setData(res.getData().getItems());
        result.setTotal(res.getData().getTotal());

        return result;
    }

    public FieldsSetting loadLawsuitFields() {
        //硬编码的获取字段逻辑
        FieldsSetting fieldsSetting = new FieldsSetting();
        fieldsSetting.setIdField("uuid");
        fieldsSetting.setFields(new ArrayList<>());
        String groupName = "developer_lawsuit";
        fieldsSetting.getFields().add(new DataApiField("uuid", groupName, "RowID", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("submit_time", groupName, "发布日期", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("doc_type", groupName, "文档类型", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("lawsuit_url", groupName, "诉讼链接", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("lawsuit_h5Url", groupName, "诉讼H5链接", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("supplier_name", groupName, "企业名称", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("title", groupName, "诉讼标题", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("court", groupName, "法院", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("judge_time", groupName, "裁决日期", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("case_type", groupName, "案件类型", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("case_reason", groupName, "案件原因", FieldType.String));

        // 返回
        return fieldsSetting;
    }

    public ListDataResult loadLawsuitData(LoadDataParams options) {
        String creditCode = options.getOptions().getContext().get("id").toString();
        BasicRiskRequestDto dto = new BasicRiskRequestDto();
        dto.setKeyword(creditCode);
        dto.setPage_num(options.getPageIndex());
        dto.setPage_size(options.getPageSize());

        BasicYcgListReponseDto res = getDeveloperDataService.getLawsuitData(dto);

        ListDataResult result = new ListDataResult();
        result.setData(res.getData().getItems());
        result.setTotal(res.getData().getTotal());

        return result;
    }


    public FieldsSetting loadTaxFields() {
        //硬编码的获取字段逻辑
        FieldsSetting fieldsSetting = new FieldsSetting();
        fieldsSetting.setIdField("uuid");
        fieldsSetting.setFields(new ArrayList<>());
        String groupName = "developer_tax";
        fieldsSetting.getFields().add(new DataApiField("uuid", groupName, "RowID", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("tax_payer_number", groupName, "税收违法公司代码", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("tax_payer_name", groupName, "税收违法公司", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("case_nature", groupName, "案件性质", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("tax_gov", groupName, "所属税务机关", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("address", groupName, "注册地址", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("illegal_content", groupName, "违法事实", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("oper_name", groupName, "法人姓名", FieldType.String));
        fieldsSetting.getFields().add(new DataApiField("illegal_time", groupName, "违法时间", FieldType.String));

        // 返回
        return fieldsSetting;
    }

    public ListDataResult loadTaxData(LoadDataParams options) {
        String creditCode = options.getOptions().getContext().get("id").toString();
        BasicRiskRequestDto dto = new BasicRiskRequestDto();
        dto.setKeyword(creditCode);
        dto.setPage_num(options.getPageIndex());
        dto.setPage_size(options.getPageSize());

        BasicYcgListReponseDto res = getDeveloperDataService.getTaxRiskData(dto);

        ListDataResult result = new ListDataResult();
        result.setData(res.getData().getItems());
        result.setTotal(res.getData().getTotal());

        return result;
    }
}
